how to find gradient of a function for vector